<template>
  <el-dialog title="用户认证" :visible.sync="dialogVisible" width="50%" append-to-body
             :close-on-click-modal="false" :before-close="close">
    <el-descriptions :column="2" border>
      <el-descriptions-item>
        <template slot="label">
          姓名
        </template>
        {{ form.nickName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          手机号码
        </template>
        {{ form.phonenumber }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          邮箱
        </template>
        {{ form.email }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          用户性别
        </template>
        <dict-tag :options="dict.type.sys_user_sex" :value="form.sex"/>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          状态
        </template>
        <dict-tag :options="dict.type.sys_normal_disable" :value="form.status"/>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          备注
        </template>
        {{ form.remark }}
      </el-descriptions-item>
    </el-descriptions>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="认证状态" prop="authStatus">
        <template>
          <el-select v-model="form.authStatus" placeholder="请选择认证状态" style="width: 100%;">
            <div v-for="(item,index) in dict.type.auth_status" :key="index">
              <el-option  :key="index" :value="item.value" :label="item.label">{{ item.label }}
              </el-option>
            </div>
          </el-select>
        </template>
      </el-form-item>
      <el-form-item label="认证意见" prop="authRemark">
        <el-input v-model="form.authRemark" type="textarea" :rows="2" placeholder="请输入认证意见" clearable/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitAuthUser">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  authUser,
  getUser, updateUser,
} from "@/api/system/user";

export default {
  name: "AuthUser",
  props: {
    dialogType: {
      type: String,
      default: "auth",
    },
    rowData: {
      type: Object,
      default: () => {
      },
    },
    dict: {}
  },
  data() {
    return {
      dialogVisible: false,
      // 岗位选项
      postOptions: [],
      // 角色选项
      roleOptions: [],
      rules: {
        authStatus: [
          {required: true, message: "请选择认证状态", trigger: "blur"},
        ],
      },
      form: {
        userId: undefined,
        deptId: undefined,
        userName: undefined,
        nickName: undefined,
        idCardNo: undefined,
        password: undefined,
        phonenumber: undefined,
        email: undefined,
        sex: undefined,
        status: "0",
        remark: undefined,
        authStatus: undefined,
        etpId: null,
        userCategory: undefined,
        declType: null,
        platforms: [],
        postIds: [],
        roleIds: [],
        authRemark: '',
        auther: '',
        authTime: null,
      }
    }
  },
  methods: {
    open(userId) {
      this.dialogVisible = true;
      this.loadDetail(userId);
    },
    close() {
      this.dialogVisible = false
    },
    // 获取详情
    loadDetail(userId) {
      getUser(userId).then((res) => {
        if (res.code == 200) {
          this.postOptions = res.posts;
          this.roleOptions = res.roles;
          this.form = res.data;
        }
      });
    },
    submitAuthUser(){
      this.$refs["form"].validate((valid) => {
        authUser(this.form).then(response => {
          this.$modal.msgSuccess("认证成功");
          this.dialogVisible = false;
          this.$emit("handleQuery");
        });
      });
    }

  }
}

</script>
